package uqbar.aspectj.observable.perthis;

import org.aspectj.lang.NoAspectBoundException;

import uqbar.aspectj.utils.SimpleObject;
import examples.perthis.TestObject;

/**
 * @author phm
 */
public class ObservablePerThisExample extends SimpleObject {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		new ObservablePerThisExample().daleMasa();
	}

	public void daleMasa() {
		TestObject obj = new TestObject();

		obj.stringField = "nuevo";
		fullLog(obj);

		obj.stringField = ("nuevo2");
		fullLog(obj);

		obj = new TestObject();
		obj.setStringField("masnuevo!");
		fullLog(obj);
	}

	private void fullLog(TestObject obj) {
		log(this);
		log(obj);
		System.out.println();
	}

	private void log(Object obj) {
		try {
			System.out.println("counter "
					+ SysoutPerthisObservableAspect.aspectOf(obj).counter + " for " + obj);
		} catch (NoAspectBoundException ex) {
			System.out.println("No aspect for " + obj);
		}
	}

}
